#!/bin/sh
source "${LMD_BASE_INSTALL_SCRIPT_DIR}/global/sys_check.sh"
# source ${LMD_BASE_INSTALL_SCRIPT_DIR}/global/alias.sh

if [ -f /etc/os-release ]; then
    echo "Linux. Not yet support."
elif [ -f /System/Library/CoreServices/SystemVersion.plist ]; then
    echo "macOS"
    APP_PATH="/Applications/Ollama.app"
    BIN_NAME=$(defaults read "${APP_PATH}/Contents/Info" CFBundleExecutable 2>/dev/null)
    cd "$APP_PATH"/Contents/MacOS/
    ./"$BIN_NAME"
    
elif current_os_is_windows; then
    echo "Windows"
    OLLAMA_ACTUAL_INSTALL_PATHS=$(where.exe "ollama app.exe" 2>/dev/null)
    if [ -z "$OLLAMA_ACTUAL_INSTALL_PATHS" ]; then
        echo "The installed Ollama could not be found."
    else
        echo "$OLLAMA_ACTUAL_INSTALL_PATHS" | while read -r path; do
            echo "found path: $path"
        done
        FIRST_PATH=$(echo "$OLLAMA_ACTUAL_INSTALL_PATHS" | head -n 1)
        echo "The first path: "$FIRST_PATH
        explorer.exe "$FIRST_PATH"
    fi
else
    echo "Unknown OS"
fi
echo "lmd start script end."
